package com.js.purs.controller;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import java.util.Locale;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurProdInfo;
import com.js.purs.service.IPurProdInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购商品信息Controller
 *
 * @author lzq
 * @date 20240617
 */
@RestController
@RequestMapping("/planInfo")
public class PurProdInfoController extends BaseController {
    @Autowired
    private IPurProdInfoService purProdInfoService;

    /**
     * 查询采购商品信息列表
     */
    @RequiresPermissions("purs:planInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(PurProdInfo purProdInfo) {
        startPage();
        List<PurProdInfo> list = purProdInfoService.selectPurProdInfoList(purProdInfo);
        return getDataTable(list);
    }

    /**
     * 导出采购商品信息列表
     */
    @RequiresPermissions("purs:planInfo:export")
    @Log(title = "采购商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurProdInfo purProdInfo) {
        List<PurProdInfo> list = purProdInfoService.selectPurProdInfoList(purProdInfo);
        ExcelUtil<PurProdInfo> util = new ExcelUtil<PurProdInfo>(PurProdInfo.class);
        util.exportExcel(response, list, "采购商品信息数据");
    }

    /**
     * 获取采购商品信息详细信息
     */
    @RequiresPermissions("purs:planInfo:query")
    @GetMapping(value = "/{prodInfoId}")
    public AjaxResult getInfo(@PathVariable("prodInfoId") Long prodInfoId) {
        return success(purProdInfoService.selectPurProdInfoByProdInfoId(prodInfoId));
    }

    /**
     * 新增采购商品信息
     */
    @RequiresPermissions("purs:planInfo:add")
    @Log(title = "采购商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurProdInfo purProdInfo) {
        return toAjax(purProdInfoService.insertPurProdInfo(purProdInfo));
    }

    /**
     * 修改采购商品信息
     */
    @RequiresPermissions("purs:planInfo:edit")
    @Log(title = "采购商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurProdInfo purProdInfo) {
        return toAjax(purProdInfoService.updatePurProdInfo(purProdInfo));
    }

    /**
     * 删除采购商品信息
     */
    @RequiresPermissions("purs:planInfo:remove")
    @Log(title = "采购商品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{prodInfoIds}")
    public AjaxResult remove(@PathVariable Long[] prodInfoIds) {
        return toAjax(purProdInfoService.deletePurProdInfoByProdInfoIds(prodInfoIds));
    }


    /**
     * 批量新增
     */
    @PostMapping("/insertBatchPlanInfo")
    public AjaxResult insertBatchPlanInfo(@RequestBody List<PurProdInfo> purProdInfos) throws ParseException {
        return toAjax(purProdInfoService.insertPlanInfoBatch(purProdInfos));
    }

    /**
     * 批量修改/新增
     */
    @PostMapping("/updateOrInsertPlanInfo")
    public AjaxResult updateOrInsertPlanInfo(@RequestBody List<PurProdInfo> purProdInfos) throws ParseException {
        return toAjax(purProdInfoService.updateOrInsertPlanInfo(purProdInfos));
    }

    /***
     * 批量删除
     */
    @PostMapping("/deletePlanInfos")
    public AjaxResult deletePlanInfos(@RequestBody List<PurProdInfo> purProdInfos) throws ParseException {
        return toAjax(purProdInfoService.deletePlanInfos(purProdInfos));
    }

    @GetMapping("/getPlanInfoNewId")
    public AjaxResult getPlanInfoNewId() throws ParseException {
        return AjaxResult.success(purProdInfoService.selectPurProdInfoNewId());
    }

    @GetMapping("/getPlanInfoListByBudgets/{planCode}")
    public TableDataInfo getPlanInfoListByBudgets(@PathVariable("planCode") String planCode) {
        startPage();
        List<PurProdInfo> list = purProdInfoService.getPlanInfoListByBudgets(planCode);
        return getDataTable(list);
    }


}
